using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace JlPay.Sdk.Models.Trans.Dto
{
    /// <summary>
    /// 优惠券信息DTO
    /// @author liaochangyi
    /// @since 2025-01-25
    /// </summary>
    public class CouponInfoDto
    {
        /// <summary>
        /// 券ID
        /// </summary>
        [JsonPropertyName("promotion_id")]
        public string? PromotionId { get; set; }

        /// <summary>
        /// 优惠名称
        /// </summary>
        [JsonPropertyName("name")]
        public string? Name { get; set; }

        /// <summary>
        /// 优惠范围
        /// </summary>
        [JsonPropertyName("scope")]
        public string? Scope { get; set; }

        /// <summary>
        /// 优惠类型
        /// </summary>
        [JsonPropertyName("type")]
        public string? Type { get; set; }

        /// <summary>
        /// 优惠券面额
        /// </summary>
        [JsonPropertyName("amount")]
        public string? Amount { get; set; }

        /// <summary>
        /// 活动ID
        /// </summary>
        [JsonPropertyName("activity_id")]
        public string? ActivityId { get; set; }

        /// <summary>
        /// 微信出资
        /// </summary>
        [JsonPropertyName("wxpay_contribute")]
        public string? WxpayContribute { get; set; }

        /// <summary>
        /// 商户出资
        /// </summary>
        [JsonPropertyName("merchant_contribute")]
        public string? MerchantContribute { get; set; }

        /// <summary>
        /// 支付宝券ID
        /// </summary>
        [JsonPropertyName("id")]
        public string? Id { get; set; }

        /// <summary>
        /// 其他出资金额
        /// </summary>
        [JsonPropertyName("other_contribute")]
        public string? OtherContribute { get; set; }

        /// <summary>
        /// 备注信息
        /// </summary>
        [JsonPropertyName("memo")]
        public string? Memo { get; set; }

        /// <summary>
        /// 券模板ID
        /// </summary>
        [JsonPropertyName("template_id")]
        public string? TemplateId { get; set; }

        /// <summary>
        /// 优惠券的其他出资方明细
        /// </summary>
        [JsonPropertyName("other_contribute_detail")]
        public string? OtherContributeDetail { get; set; }

        /// <summary>
        /// 买家出资
        /// </summary>
        [JsonPropertyName("purchase_buyer_contribute")]
        public string? PurchaseBuyerContribute { get; set; }

        /// <summary>
        /// 商户出资
        /// </summary>
        [JsonPropertyName("purchase_merchant_contribute")]
        public string? PurchaseMerchantContribute { get; set; }

        /// <summary>
        /// 内部出资
        /// </summary>
        [JsonPropertyName("purchase_ant_contribute")]
        public string? PurchaseAntContribute { get; set; }

        /// <summary>
        /// 出资方
        /// </summary>
        [JsonPropertyName("spnsr_id")]
        public string? SpnsrId { get; set; }

        /// <summary>
        /// 优惠金额
        /// </summary>
        [JsonPropertyName("offst_amt")]
        public string? OffstAmt { get; set; }

        /// <summary>
        /// 项目简称
        /// </summary>
        [JsonPropertyName("desc")]
        public string? Desc { get; set; }

        /// <summary>
        /// 附加信息
        /// </summary>
        [JsonPropertyName("addn_info")]
        public string? AddnInfo { get; set; }

        /// <summary>
        /// 项目发行方
        /// </summary>
        [JsonPropertyName("issuer_id")]
        public string? IssuerId { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public CouponInfoDto()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="couponDict">优惠券信息字典</param>
        public CouponInfoDto(Dictionary<string, object>? couponDict)
        {
            if (couponDict != null)
            {
                PromotionId = couponDict.TryGetValue("promotion_id", out var promotionId) ? promotionId?.ToString() : null;
                Name = couponDict.TryGetValue("name", out var name) ? name?.ToString() : null;
                Scope = couponDict.TryGetValue("scope", out var scope) ? scope?.ToString() : null;
                Type = couponDict.TryGetValue("type", out var type) ? type?.ToString() : null;
                Amount = couponDict.TryGetValue("amount", out var amount) ? amount?.ToString() : null;
                ActivityId = couponDict.TryGetValue("activity_id", out var activityId) ? activityId?.ToString() : null;
                WxpayContribute = couponDict.TryGetValue("wxpay_contribute", out var wxpayContribute) ? wxpayContribute?.ToString() : null;
                MerchantContribute = couponDict.TryGetValue("merchant_contribute", out var merchantContribute) ? merchantContribute?.ToString() : null;
                Id = couponDict.TryGetValue("id", out var id) ? id?.ToString() : null;
                OtherContribute = couponDict.TryGetValue("other_contribute", out var otherContribute) ? otherContribute?.ToString() : null;
                Memo = couponDict.TryGetValue("memo", out var memo) ? memo?.ToString() : null;
                TemplateId = couponDict.TryGetValue("template_id", out var templateId) ? templateId?.ToString() : null;
                OtherContributeDetail = couponDict.TryGetValue("other_contribute_detail", out var otherContributeDetail) ? otherContributeDetail?.ToString() : null;
                PurchaseBuyerContribute = couponDict.TryGetValue("purchase_buyer_contribute", out var purchaseBuyerContribute) ? purchaseBuyerContribute?.ToString() : null;
                PurchaseMerchantContribute = couponDict.TryGetValue("purchase_merchant_contribute", out var purchaseMerchantContribute) ? purchaseMerchantContribute?.ToString() : null;
                PurchaseAntContribute = couponDict.TryGetValue("purchase_ant_contribute", out var purchaseAntContribute) ? purchaseAntContribute?.ToString() : null;
                SpnsrId = couponDict.TryGetValue("spnsr_id", out var spnsrId) ? spnsrId?.ToString() : null;
                OffstAmt = couponDict.TryGetValue("offst_amt", out var offstAmt) ? offstAmt?.ToString() : null;
                Desc = couponDict.TryGetValue("desc", out var desc) ? desc?.ToString() : null;
                AddnInfo = couponDict.TryGetValue("addn_info", out var addnInfo) ? addnInfo?.ToString() : null;
                IssuerId = couponDict.TryGetValue("issuer_id", out var issuerId) ? issuerId?.ToString() : null;
            }
        }

        /// <summary>
        /// 转换为字典格式
        /// </summary>
        /// <returns>字典数据</returns>
        public Dictionary<string, object?> ToDictionary()
        {
            return new Dictionary<string, object?>
            {
                ["promotion_id"] = PromotionId,
                ["name"] = Name,
                ["scope"] = Scope,
                ["type"] = Type,
                ["amount"] = Amount,
                ["activity_id"] = ActivityId,
                ["wxpay_contribute"] = WxpayContribute,
                ["merchant_contribute"] = MerchantContribute,
                ["id"] = Id,
                ["other_contribute"] = OtherContribute,
                ["memo"] = Memo,
                ["template_id"] = TemplateId,
                ["other_contribute_detail"] = OtherContributeDetail,
                ["purchase_buyer_contribute"] = PurchaseBuyerContribute,
                ["purchase_merchant_contribute"] = PurchaseMerchantContribute,
                ["purchase_ant_contribute"] = PurchaseAntContribute,
                ["spnsr_id"] = SpnsrId,
                ["offst_amt"] = OffstAmt,
                ["desc"] = Desc,
                ["addn_info"] = AddnInfo,
                ["issuer_id"] = IssuerId
            };
        }
    }
} 